﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Media3D;

namespace Perspective.Wpf3D.Primitives
{
    /// <summary>
    /// 包含立方体特征的三维模型基类
    /// Basic abstract class for Perspective.Wpf3D elements with 
    /// an inner GeometryModel3D with box dimensions.  
    /// </summary>
    public class BoxElement3D : GeometryElement3D
    {
        #region Constructors

        /// <summary>
        /// Static constructor.
        /// No default back material for 3D closed shapes.
        /// </summary>
        static BoxElement3D()
        {
            BackMaterialProperty.OverrideMetadata(
                typeof(BoxElement3D),
                new PropertyMetadata(
                    null,
                    VisualPropertyChanged));

            DefaultTextureMappingProperty.OverrideMetadata(
                typeof(BoxElement3D),
                new PropertyMetadata(
                    true));
        }

        #endregion

        #region Properties

        #region VisibleSides 可见的面

        /// <summary>
        /// 可见的面
        /// Gets or sets the sides of the model.
        /// Default is BoxSides.All
        /// XAML usage : VisibleSides="Back,Left,Right,Up,Down"
        /// </summary>
        public BoxSides VisibleSides
        {
            get { return (BoxSides)GetValue(VisibleSidesProperty); }
            set { SetValue(VisibleSidesProperty, value); }
        }

        /// <summary>
        /// Identifies the VisibleSides dependency property.
        /// </summary>
        public static readonly DependencyProperty VisibleSidesProperty =
            DependencyProperty.Register(
                "VisibleSides",
                typeof(BoxSides),
                typeof(BoxElement3D),
                new UIPropertyMetadata(
                    BoxSides.All,
                    VisualPropertyChanged));
        #endregion

        #region Length  长度 X轴宽度

        /// <summary>
        /// Gets or sets the Length possible Value of the ThicknessBox element. 
        /// This is a dependency property.
        /// </summary>
        public double Length
        {
            get { return (double)GetValue(LengthProperty); }
            set { SetValue(LengthProperty, value); }
        }

        /// <summary>
        /// Identifies the Length dependency property.
        /// </summary>
        public static readonly DependencyProperty LengthProperty =
            DependencyProperty.Register(
                "Length",
                typeof(double),
                typeof(BoxElement3D),
                new PropertyMetadata(
                    1.0,
                    VisualPropertyChanged),
                    PositiveDoubleValidateValue);

        #endregion

        #region Width 宽度 Z宽度
        /// <summary>
        /// Gets or sets the Width possible Value of the ThicknessBox element. 
        /// This is a dependency property.
        /// </summary>
        public double Width
        {
            get { return (double)GetValue(WidthProperty); }
            set { SetValue(WidthProperty, value); }
        }

        /// <summary>
        /// Identifies the Width dependency property.
        /// </summary>
        public static readonly DependencyProperty WidthProperty =
            DependencyProperty.Register(
                "Width",
                typeof(double),
                typeof(BoxElement3D),
                new PropertyMetadata(
                    1.0,
                    VisualPropertyChanged),
                    PositiveDoubleValidateValue);
        #endregion

        #region Height 高度 Y宽度
        /// <summary>
        /// Gets or sets the Height possible Value of the ThicknessBox element. 
        /// This is a dependency property.
        /// </summary>
        public double Height
        {
            get { return (double)GetValue(HeightProperty); }
            set { SetValue(HeightProperty, value); }
        }

        /// <summary>
        /// Identifies the Height dependency property.
        /// </summary>
        public static readonly DependencyProperty HeightProperty =
            DependencyProperty.Register(
                "Height",
                typeof(double),
                typeof(BoxElement3D),
                new PropertyMetadata(
                    1.0,
                    VisualPropertyChanged),
                    PositiveDoubleValidateValue);
        #endregion

        #endregion
    }
}
